<html>
<head><meta charset="utf-8"><title>coinductive sized · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html">coinductive sized</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="235842264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/235842264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#235842264">(Apr 23 2021 at 13:43)</a>:</h4>
<p>I will say <span class="user-mention" data-user-id="216206">@lcnr</span> that I don't see a reason that <code>Sized</code> can't be coinductive</p>



<a name="235842279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/235842279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#235842279">(Apr 23 2021 at 13:43)</a>:</h4>
<p>it's probably the easiest case of all</p>



<a name="235842291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/235842291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#235842291">(Apr 23 2021 at 13:43)</a>:</h4>
<p>given that we don't permit user impls at all</p>



<a name="236305963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236305963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236305963">(Apr 27 2021 at 09:17)</a>:</h4>
<p>interestingly, with my change the following does not error with <code>cargo check</code></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Assoc</span>: <span class="o">?</span><span class="nb">Sized</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">A</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span>::<span class="n">Assoc</span><span class="p">);</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="236306070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236306070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236306070">(Apr 27 2021 at 09:18)</a>:</h4>
<p>which we should prevent imo</p>



<a name="236306172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236306172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236306172">(Apr 27 2021 at 09:19)</a>:</h4>
<p>the following doesn't error at all on stable, even though <code>Foo&lt;()&gt;</code> is a self recursive type</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Assoc</span>: <span class="o">?</span><span class="nb">Sized</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">A</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span>::<span class="n">Assoc</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="236306186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236306186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236306186">(Apr 27 2021 at 09:19)</a>:</h4>
<p>which i would also like to error on eagerly</p>



<a name="236306498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236306498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236306498">(Apr 27 2021 at 09:22)</a>:</h4>
<p>does it make sense to require types to not be self recursive for wf?</p>



<a name="236311310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236311310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236311310">(Apr 27 2021 at 10:05)</a>:</h4>
<p>people call me mc stack overflow <span aria-label="sparkles" class="emoji emoji-2728" role="img" title="sparkles">:sparkles:</span> because i find stack overflows</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">y</span>: <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Bar</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">Bar</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="236313592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236313592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236313592">(Apr 27 2021 at 10:26)</a>:</h4>
<p>that cycle is actually kind of hard to fix <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="236314802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236314802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236314802">(Apr 27 2021 at 10:39)</a>:</h4>
<p><span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> there has to be a way to cleanly represent this as a graph :/</p>



<a name="236314929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236314929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236314929">(Apr 27 2021 at 10:40)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/84611">#84611</a></p>



<a name="236315283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315283">(Apr 27 2021 at 10:45)</a>:</h4>
<p>okay...</p>



<a name="236315313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315313">(Apr 27 2021 at 10:45)</a>:</h4>
<p>so ignoring generic parameters, we have a fairly simple directed graph</p>



<a name="236315342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315342">(Apr 27 2021 at 10:45)</a>:</h4>
<p>(we don't look into projections or anything, so you can only directly embed a type or not at all)</p>



<a name="236315534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315534">(Apr 27 2021 at 10:47)</a>:</h4>
<p>for a parameter to matter is has to be used directly somewhere</p>



<a name="236315546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315546">(Apr 27 2021 at 10:48)</a>:</h4>
<p>if we now have <code>Bar&lt;Foo&lt;T&gt;&gt;</code></p>



<a name="236315629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315629">(Apr 27 2021 at 10:48)</a>:</h4>
<p>both <code>Bar</code> and <code>Foo</code> have to directly use their parameter</p>



<a name="236315846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315846">(Apr 27 2021 at 10:50)</a>:</h4>
<p>how to compute "directly use their parameter", that's again recursive <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="236315898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315898">(Apr 27 2021 at 10:51)</a>:</h4>
<p>i don't get it :(</p>



<a name="236315920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236315920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236315920">(Apr 27 2021 at 10:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/144729-wg-traits/topic/coinductive.20sized/near/236314802">said</a>:</p>
<blockquote>
<p><span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> there has to be a way to cleanly represent this as a graph :/</p>
</blockquote>
<p>xx</p>



<a name="236316661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236316661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236316661">(Apr 27 2021 at 10:58)</a>:</h4>
<p>there might not be <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> considering that finding cycles in a graph is really fast and i would assume this to not be that easy</p>



<a name="236317273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236317273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236317273">(Apr 27 2021 at 11:04)</a>:</h4>
<p>so, the quickest fix would be to change <a href="https://github.com/rust-lang/rust/blob/e1886935b78e62a6c23a243e48f81815ae7fd141/compiler/rustc_middle/src/ty/util.rs#L1012">https://github.com/rust-lang/rust/blob/e1886935b78e62a6c23a243e48f81815ae7fd141/compiler/rustc_middle/src/ty/util.rs#L1012</a> to check if <code>ty</code> is not the same as <code>seen</code> type but whether the substs of <code>seen_type</code> are directly mentioned in <code>ty</code></p>



<a name="236317323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236317323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236317323">(Apr 27 2021 at 11:04)</a>:</h4>
<p>but that doesn't seem too nice, so i would like there to be a cleaner approach here</p>



<a name="236320597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236320597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236320597">(Apr 27 2021 at 11:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/144729-wg-traits/topic/coinductive.20sized/near/236317273">said</a>:</p>
<blockquote>
<p>so, the quickest fix would be to change <a href="https://github.com/rust-lang/rust/blob/e1886935b78e62a6c23a243e48f81815ae7fd141/compiler/rustc_middle/src/ty/util.rs#L1012">https://github.com/rust-lang/rust/blob/e1886935b78e62a6c23a243e48f81815ae7fd141/compiler/rustc_middle/src/ty/util.rs#L1012</a> to check if <code>ty</code> is not the same as <code>seen</code> type but whether the substs of <code>seen_type</code> are directly mentioned in <code>ty</code></p>
</blockquote>
<p>that might not actually work :////  because checking that the substs of <code>seen_type</code> are directly mentioned in <code>ty</code> is the same problem again <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="236320912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236320912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236320912">(Apr 27 2021 at 11:38)</a>:</h4>
<p>just going to ignore this for now <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="236321359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236321359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236321359">(Apr 27 2021 at 11:42)</a>:</h4>
<p>slightly different scenario in <a href="https://github.com/rust-lang/rust/issues/74224">#74224</a>, it finds ContainsRecursive , but it still tries to find SelfRecursive, so doesn't stop either.</p>



<a name="236449441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236449441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236449441">(Apr 28 2021 at 04:38)</a>:</h4>
<p>/me wonders if this is just the halting problem in disguise</p>



<a name="236476159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236476159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236476159">(Apr 28 2021 at 09:27)</a>:</h4>
<p>/me wondered the same thing, but really hopes checking whether types are recursive is not turing complete :p</p>



<a name="236492562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236492562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> FireFighterDuck <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236492562">(Apr 28 2021 at 11:49)</a>:</h4>
<p>FWIW Chalk seems to accept the stack-overflowing example (or at least my attempt to make a test out of it) as wellformed without any problems. Based on how Chalk handles (co-)inductive cycles of goals, I also can't imagine that it would be as hard as the halting problem, though <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="236492864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236492864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236492864">(Apr 28 2021 at 11:52)</a>:</h4>
<p>like, this is a well formed type but not a representable one</p>
<p>does chalk already error for something like <code>struct Foo(Foo);</code>, i think that might be outside of chalk's responsibilities</p>



<a name="236949147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236949147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236949147">(May 01 2021 at 08:17)</a>:</h4>
<p>This family of examples is roughly why auto traits have to be coinductive</p>



<a name="236949196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236949196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236949196">(May 01 2021 at 08:18)</a>:</h4>
<p>Or at least I haven't found a way around it, although I would like to</p>



<a name="236949231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236949231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236949231">(May 01 2021 at 08:19)</a>:</h4>
<p>e.g. for <code>Vec&lt;T&gt;</code> you can readily imagine an algorithm that examines its structure and generates an impl like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Send</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">T</span>: <span class="nb">Send</span> <span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="236949305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236949305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236949305">(May 01 2021 at 08:20)</a>:</h4>
<p>but for a struct like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">Iterator</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">T</span>::<span class="n">Item</span><span class="o">&gt;&gt;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>it's hard to imagine anything other than</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Send</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">T</span>::<span class="n">Item</span>: <span class="nb">Send</span> <span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>and of course <code>T::Item</code> might well be <code>Foo&lt;T&gt;</code>.</p>



<a name="236949347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236949347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236949347">(May 01 2021 at 08:21)</a>:</h4>
<p>What was the bug, <span class="user-mention" data-user-id="216206">@lcnr</span>, that we thought <code>Sized</code> being coinductive might help with? I forget.</p>



<a name="236979946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/coinductive%20sized/near/236979946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/coinductive.20sized.html#236979946">(May 01 2021 at 16:10)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> you mean <a href="https://github.com/rust-lang/rust/issues/80626">#80626</a>?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>